package test.app.core.demo.controller;


import junit.framework.Assert;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

public class Index2Controller extends JUnitActionBase {

	@BeforeClass
	public static void beforeClass() throws Exception {
		System.out.println("##################junit测试开始##################");
	}

	@Test
	public void testAdd() throws Exception {
	    MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setRequestURI("/index");
        request.setServletPath("/index");  
        request.addParameter("name", "张三");  
        request.addParameter("password", "123456");
        request.setMethod("POST");
        request.setAttribute("msg", "测试action成功");  
        try{
            final ModelAndView mav = this.excuteAction(request, response);
            Assert.assertEquals("index", mav.getViewName());  
            System.out.println("模板名称:" + mav.getViewName());
            
            String msg1=(String)request.getAttribute("model");  
            System.out.println(msg1);
            
//            Object msg2 = mav.getModelMap().get("model");
//            System.out.println(" = " + msg2);
            
        }catch (Exception e){
            e.printStackTrace();
        }
	}

	@AfterClass
	public static void afterClass() throws Exception {
		System.out.println("##################junit测试结束##################");
	}
}
